<?php
/* 
 *广告图片管理
 */
class AdAction extends CommonAction {
    public function _filter(&$map) {
        $key = trim($_REQUEST['keywords']);
        if(!empty($key)) {
            $map['name'] = array('like',"%".$key."%");//网站名称
            $map['url'] = array('like',"%".$key."%");//url
            $map['_logic'] = "or";
        }
    }


    public function insert() {
        $Hotel = D('Ad');
        if(false == $Hotel->create()) {
            $this->error($Hotel->getError());
        }
        if(false !== $list = $Hotel->add()) {
            $this->process_photo($list,2);
            $this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
            $this->success('广告添加成功');
        }
        else {
            $this->error('新增广告失败！');
        }
    }

    function _before_edit(){
        $Attach = M('Attach');
        $logo = $Attach ->where('form_id ='.$_REQUEST['id'].' and attachfunc = 2')->field('id,filename,path')->find();
        if(!empty($logo['filename'])){
            $this -> assign('logo_photo',__ROOT__.substr($logo['path'],1).'thumb_'.$logo['filename']);
        }
    }

    public function update(){
        $id = intval($_POST['id']);
        if($id <= 0){
            $this->error('编辑的广告不合法！');
        }
        $Hotel = D('Ad');
        if(false == $Hotel->create()) {
            $this->error($Hotel->getError());
        }
        if(false !== $list = $Hotel->save()) {
            $this->process_photo($id,2);
            $this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
            $this->success('广告修改成功');
        }
        else {
            $this->error('广告修改失败！');
        }
    }

}
?>
